//
//  FootViewMember.m
//  shanHaiHuiApp
//
//  Created by 小和尚 on 2018/3/14.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "FootViewMember.h"
@interface FootViewMember()<UITextFieldDelegate,UITextViewDelegate>

@end
@implementation FootViewMember


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _personLabel = [[UILabel alloc] init];
        _personLabel.text = @"收货人:";
        _personLabel.font = DEF_FontSize_13;
        _personLabel.textColor = getColor(@"6A6A6A");
        
        _personTextField = [[UITextField alloc] init];
        _personTextField.font = DEF_FontSize_13;
        _personTextField.textColor = getColor(@"323232");
        _personTextField.placeholder = @"请输入收货人";
        _personTextField.delegate = self;
        
        _personTextField.inputAccessoryView = [self addToolbar];
        
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = getColor(@"F0F0F0");
        
        _contactLabel = [[UILabel alloc] init];
        _contactLabel.text = @"联系方式:";
        _contactLabel.font = DEF_FontSize_13;
        _contactLabel.textColor = getColor(@"6A6A6A");
        
        _contactTextField = [[UITextField alloc] init];
        _contactTextField.font = DEF_FontSize_13;
        _contactTextField.textColor = getColor(@"323232");
        _contactTextField.placeholder = @"请输入联系方式";
        _contactTextField.inputAccessoryView = [self addToolbar];
        _contactTextField.keyboardType = UIKeyboardTypeNumberPad;
        
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = getColor(@"F0F0F0");
        
        _adressLabel = [[UILabel alloc] init];
        _adressLabel.text = @"配送地址:";
        _adressLabel.font = DEF_FontSize_13;
        _adressLabel.textColor = getColor(@"6A6A6A");
        
        _adressTextField = [[UITextField alloc] init];
        _adressTextField .font = DEF_FontSize_13;
        _adressTextField .textColor = getColor(@"323232");
        _adressTextField .placeholder = @"请输入配送地址";
        _adressTextField.inputAccessoryView = [self addToolbar];
        
        _lineView3 = [[UIView alloc] init];
        _lineView3.backgroundColor = getColor(@"F0F0F0");
        
        _remarkLabel = [[UILabel alloc] init];
        _remarkLabel.font = DEF_FontSize_13;
        _remarkLabel.textColor = getColor(@"6A6A6A");
        _remarkLabel.text = @"配送备注:";
        
        _remarkView = [[UITextView alloc] init];
        _remarkView.font = DEF_FontSize_13;
        _remarkView.textColor = getColor(dividerColor);
        _remarkView.layer.borderColor = getColor(dividerColor).CGColor;
        _remarkView.layer.borderWidth = 1;
        _remarkView.delegate = self;
        _remarkView.inputAccessoryView = [self addToolbar];
        
        
        [self sd_addSubviews:@[self.personLabel,self.personTextField,self.contactLabel,self.contactTextField,self.adressLabel,self.adressTextField,self.remarkLabel,self.remarkView,self.lineView1,self.lineView2,self.lineView3]];
        
        [self layOutFrame];
    }
    return self;
}

- (void)layOutFrame{
    ws(self)
    [self.personLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.width.mas_equalTo(UNIT_WIDTH(70));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.personTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.personLabel.mas_right).offset(UNIT_WIDTH(15));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.personLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        
    }];
    
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.personLabel.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.contactLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.lineView1.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        make.width.mas_equalTo(UNIT_WIDTH(70));
    }];
    
    [self.contactTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.contactLabel.mas_right).offset(UNIT_WIDTH(15));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.contactLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.contactLabel.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    
       make.top.mas_equalTo(weakself.lineView2.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        make.width.mas_equalTo(UNIT_WIDTH(70));
    }];
    
    [self.adressTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.adressLabel.mas_right).offset(UNIT_WIDTH(15));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.adressLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(50));
    }];
    
    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.adressLabel.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.lineView3.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.remarkView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.remarkLabel.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.height.mas_equalTo(UNIT_HEIGHT(100));
    }];
    
}

- (UIToolbar *)addToolbar
{
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(numberFieldCancle)];
    //toolbar.items = @[bar];
    
    toolbar.items = @[space, bar];
    
    return toolbar;
}

- (void)numberFieldCancle{
    
    [self.personTextField resignFirstResponder];
    
    [self.contactTextField resignFirstResponder];
    
    [self.adressTextField resignFirstResponder];
    
    [self.remarkView resignFirstResponder];
    
}


@end
